/**
 * 文件名称:  EncodingFilter.java
 * 文件版权:  SunShade Technologies Co., Ltd. Copyright 2000-2020,  All rights reserved
 * 文件描述:  <描述>
 * 修改作者:  LiXiangDong
 * 修改时间:  Jan 10, 2013
 * 修改单号:  <修改单号>
 * 修改内容:  <修改内容>
 */
package com.sunshade.common.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;

/**
 * 
 * @author  LiXiangDong
 * @version V1.0, Jan 10, 2013
 */
public class EncodingFilter extends HttpServlet implements Filter
{
    /** 注释内容 */
    private static final long serialVersionUID = 6772125110233497434L;

    private static final String CONTENT_TYPE = "text/html;charset=UTF-8";
    
    private String targetEncoding = "UTF-8";
    
    /** 初始化 */
    public void init(FilterConfig config)
        throws ServletException
    {
        this.targetEncoding = config.getInitParameter("encoding");
    }
    
    /** 过滤器 */
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException
    {
        request.setCharacterEncoding(targetEncoding);
        response.setContentType(CONTENT_TYPE);
        if (chain != null)
        {
            chain.doFilter(request, response);
        }
    }
}
